package com.bjpowernode.crm.web.controller;

import com.bjpowernode.crm.pojo.Remark;
import com.bjpowernode.crm.pojo.User;
import com.bjpowernode.crm.service.RemarkService;
import com.bjpowernode.crm.utils.UUIDUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("remark")
@ResponseBody
public class remarkController {

    @Resource
    private RemarkService remarkService;

    @RequestMapping("showRemark.json")
    public List<Remark> getAllRemark(){
        return remarkService.getAllRemark();
    }


    //添加备注
    @RequestMapping("addRemark.do")
    public Map addRemark(String noteContent, String marketingActivitiesId, Remark remark, HttpSession session){
        System.out.println(marketingActivitiesId);
        //创建id
        remark.setId(UUIDUtil.getUUID());
        //创建添加人
        User user = (User) session.getAttribute("loginUser");
        remark.setNotePerson(user.getLoginAct()+"|"+user.getName());
        //创建添加备注的时间：就是此时此刻
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取当前时间
        Date date = new Date();
        String format = sdf.format(date);
        //设置当前时间为备注创建的时间
        remark.setNoteTime(format);
        //设置外键
        remark.setMarketingActivitiesId(marketingActivitiesId);
        //设置备注内容
        remark.setNoteContent(noteContent);
        remarkService.addRemark(remark);


        return new HashMap(){{
           put("success",true);
           put("msg","添加备注成功");
        }};
    }
}
